#include "stdio.h"
#include "pthread.h"
#include "unistd.h"
#include "sys/types.h"
#include "string.h"
#include "stdlib.h"


void printf_id(const char *str)
{
    pid_t pid;
    pthread_t tid;

    pid = getpid();
    tid = pthread_self();

    printf("%s, pid is %d, tid is %lu\n", str, pid, tid);
}

void *thread_start(void *argv)
{
    if(!strncmp("1", (char *)argv, sizeof("1"))){
        printf("child thread return\n");
        return (void *)1;
    }else if(!strncmp("2", (char *)argv, sizeof("2"))){
        printf("child thread pthread_exit\n");
        pthread_exit((void *)2);
    }else if(!strncmp("3", (char *)argv, sizeof("3"))){
        printf("child thread exit\n");
        exit(3);
    }
}


int main(int argc, char *argv[])
{
    int ret;
    pthread_t tid;

    ret = pthread_create(&tid, NULL, thread_start, (void *)argv[1]);

    if(ret != 0){
        printf("thread create failed\n");
        return 0;
    }

    sleep(2);
    
    printf("main thread exit\n");

    return 0;
}
